# Contributor: Łukasz Jendrysik <scadu@yandex.com>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=gnokii
pkgver=0.6.31
pkgrel=10
pkgdesc="Tools and user space driver for use with mobile phones"
url="http://www.gnokii.org/"
arch="all"
license="GPL-2.0-or-later"
subpackages="$pkgname-dev $pkgname-doc $pkgname-libs xgnokii $pkgname-smsd
	$pkgname-smsd-pgsql:pgsql $pkgname-smsd-mysql:mysql
	$pkgname-smsd-sqlite:sqlite $pkgname-lang"

makedepends="gtk+-dev mariadb-connector-c-dev intltool libusb-compat-dev libxpm-dev
	bluez-dev libical-dev postgresql-dev sqlite-dev
	autoconf automake libtool gettext-dev"
source="http://www.gnokii.org/download/gnokii/gnokii-$pkgver.tar.bz2
	gnokii.patch
	xgnokii.patch
	gnokii-0.6.31-gcc5.patch
	"

prepare() {
	default_prepare
	update_config_sub
	sed -i 's|cellphone|phone|' xgnokii/xgnokii.desktop.in
}

build() {
	CFLAGS="$CFLAGS -std=gnu89" \
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--enable-security \
		--disable-unix98test \
		--disable-phonet \
		--with-x
	make
}

package() {
	make DESTDIR="$pkgdir" install
}

libs() {
	pkgdesc="gnokii shared libraries"
	replaces="libgnokii"
	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/libgnokii.so.* "$subpkgdir"/usr/lib/
}

xgnokii() {
	pkgdesc="Gtk+ gnokii application"
	mkdir -p "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/xgnokii "$subpkgdir"/usr/bin/
}

smsd() {
	pkgdesc="SMS Daemon for mobile phones"
	mkdir -p "$subpkgdir"/usr/bin/
	mv "$pkgdir"/usr/bin/smsd "$subpkgdir"/usr/bin/
}

pgsql() {
	pkgdesc="SMSD plugin for PostgreSQL storage backend"
	depends="gnokii-smsd"
	mkdir -p "$subpkgdir"/usr/lib/smsd
	mv "$pkgdir"/usr/lib/smsd/*pq.so "$subpkgdir"/usr/lib/smsd/
}

mysql() {
	pkgdesc="SMSD plugin for MySQL storage backend"
	depends="gnokii-smsd"
	mkdir -p "$subpkgdir"/usr/lib/smsd
	mv "$pkgdir"/usr/lib/smsd/*mysql.so "$subpkgdir"/usr/lib/smsd/
}

sqlite() {
	pkgdesc="SMSD plugin for SQLite storage backend"
	depends="gnokii-smsd"
	mkdir -p "$subpkgdir"/usr/lib/smsd
	mv "$pkgdir"/usr/lib/smsd/*sqlite*.so "$subpkgdir"/usr/lib/smsd/
}
sha512sums="529f6d0d29873f48ac00cf7151ba35dcbd93405ab27d69848ed17dea73f4fba71721d1811d921441b4214777b9b33f760b372631627cc108eb94c39684da343d  gnokii-0.6.31.tar.bz2
a253cd0a461b06b3d11202f36c518f6364705008c36d4e7ecd292ecd2e4288e42fbd55110405c6bb2d2d82499e047876aa92a9292b629d1323189a9164359d32  gnokii.patch
b7033907d8bca55366b09ef976e1f1e48a31ef2630e55770200fc3818c1a36aa6478bc73cb4f180b469d21157ad5af389dc075280f22251b7402d7ab584f37dc  xgnokii.patch
548a32f93b059e45c8616dedf49a0ce3b0e63463f8ddc3384b473d91bd12c3fab2c6e21de0b09d2b330c189454a2bf3e486aa25122ea58392d9cb11994592086  gnokii-0.6.31-gcc5.patch"
